//
//  FKChooseLogisticsVC.m
//  WanTao
//
//  Created by Macbook Pro on 2019/4/3.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKChooseLogisticsVC.h"
#import "FKChooseLogisticsCell.h"
#import "FKAddOtherLogisticsVC.h"

@interface FKChooseLogisticsVC ()

@property (nonatomic, strong) NSArray *datas;

@end

@implementation FKChooseLogisticsVC

- (NSArray *)datas
{
    if (!_datas) {
        _datas = [NSArray array];
    }
    return _datas;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"选择物流公司";
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.tableView.tableFooterView = [UIView new];
    [self loadData];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FKChooseLogisticsCell *cell = [FKChooseLogisticsCell cellWith:tableView];
    cell.data = self.datas[indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 48;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *data = self.datas[indexPath.row];
    if ([data[@"name"] isEqualToString:@"其他"]) {
        FKAddOtherLogisticsVC *vc = [[FKAddOtherLogisticsVC alloc] init];
        vc.data = data;
        fkPushNav(vc);
    } else {
        if (self.chooseLogisticBlock) {
            self.chooseLogisticBlock(data);
        }
        fkPopVC;
    }
}

#pragma mark - 网络请求
- (void)loadData
{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"order_refund_id"] = self.order_refund_id;
    [FKHttpTool postWithSuffix:@"/OrderRefund/fillExpress" param:param success:^(FKBaseResult *result) {
        if (result.isSuccess) {
            self.datas = result.data[@"express"];
            [self.tableView reloadData];
        }
    } failure:nil];
}

@end
